﻿//https://leetcode.cn/problems/evaluate-reverse-polish-notation/?envType=problem-list-v2&envId=array

class Solution {
public:
    int evalRPN(vector<string>& tokens)
    {
        stack<int> st;
        for (auto& e : tokens)
        {
            //是符号就取数字运算
            if (e == "+" || e == "-" || e == "/" || e == "*")
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();

                switch (e[0])
                {
                case '+':
                    st.push(left + right);
                    break;
                case '-':
                    st.push(left - right);
                    break;
                case '*':
                    st.push(left * right);
                    break;
                case '/':
                    st.push(left / right);
                    break;
                }
            }
            else
            {
                //数字入栈
                st.push(stoi(e));
            }
        }
        return st.top();

    }
};
